#include "connectivity.h"

Connectivity::Connectivity() : sampleInterval(10) {
    connectToBimosBox();
    /**
      DEBUG
      */
    //handle = 0;

    dataGrabber = new DataGrabber(handle);
    dataGrabber->setInterval(sampleInterval);
    qDebug() << "timeHandle started";
}


void Connectivity::setSampleInterval(int interval){
    sampleInterval = interval;
    stop();
    dataGrabber->setInterval(sampleInterval);
    start();
}


void Connectivity::connectToBimosBox() {

    handle = DapiOpenModule(RO_ETH,0);

    if (DapiGetLastError() != 0) {
        char msg[500];
        DapiGetLastErrorText((unsigned char*) msg, sizeof(msg));
        qDebug() << "Connection could not be established! Error: " << QString::fromLocal8Bit(msg);
        return;
    }

    qDebug() << "Module handle = " << handle;

}


void Connectivity::start(){
    dataGrabber->start(sampleInterval);
}

void Connectivity::stop(){
    dataGrabber->stop();
}


